%==========================================================================
%=  This file is part of the Sound Restoration Project
%=  (c) Copyright Industrial Mathematics Institute
%=                University of South Carolina, Department of Mathematics
%=  ALL RIGHTS RESERVED
%=
%=  Author: Borislav Karaivanov
%==========================================================================

%==========================================================================
% List of the files on which this procedure depends:
%
% none
%
%==========================================================================

%==========================================================================
% The function "getBitDepthFromVideoObject" gets the bit depth per color
% channel for a given Matlab-generated video object.
% INPUT: "videoObj" is a Matlab-generated video object.
% OUTPUT: "bitDepth" returns the number of bits used to encode each pixel
% value in any single color channel.
%==========================================================================
function bitDepth = getBitDepthFromVideoObject(videoObj)

% Read in the first frame.
imageArr = read(videoObj, 1);

% Find the bit depth per color channel. For instance, Matlab reports three
% 8-bit channels as 24 bits per pixel.
if (ismatrix(imageArr) == true)
    bitDepth = videoObj.BitsPerPixel;
else
    bitDepth = videoObj.BitsPerPixel/size(imageArr, 3);
end

return;
% end of the function "getBitDepthFromVideoObject"
